import urllib.request
import urllib.parse
import json

# get请求，获取豆瓣第一页数据
url = "https://movie.douban.com/j/chart/top_list?type=5&interval_id=100%3A90&action=&start=0&limit=20"
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36'
}

request = urllib.request.Request(url=url, headers=headers)
response = urllib.request.urlopen(request)
content = response.read().decode('utf-8')
# print(content)
# 将数据保存到本地 ctrl + alt + l
# open方法默认使用的是gbk编码
# fp = open("douban.json", "w", encoding="utf-8")
# fp.write(content)
# fp.close()

with open("douban1.json", "w", encoding="utf-8") as fp:
    fp.write(content)

fp.close()